clear all
set more off
set scheme s2color
cd ""

use "sample.dta", clear

****************
* Subfigure (1)
****************

* Generate time-to-event dummies

tab rel_time, gen(rel_w)

forvalue i = 1/31 {
local j = `i' - 11
label var rel_w`i' "`j'"
}

qui: reghdfe d_movein rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store d_movein

#delimit ;
coefplot d_movein, 
         vertical recast(scatter) keep(rel_w*) omitted
         order(rel_w1 rel_w2 rel_w3 rel_w4 rel_w5 rel_w6 rel_w7 rel_w8 rel_w9 rel_w10
               rel_w11 rel_w12 rel_w13 rel_w14 rel_w15 rel_w16 rel_w17 rel_w18 rel_w19 rel_w20 
               rel_w21 rel_w22 rel_w23 rel_w24 rel_w25 rel_w26 rel_w27 rel_w28 rel_w29 rel_w30 rel_w31)
         msymbol(Oh) mcolor(gs5) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(gs5))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0, lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash))
         ylabel(-20(5)10, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr

****************
* Subfigure (2)
****************

qui: reghdfe d_movein rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp if faction == 1, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store d_movein_f

qui: reghdfe d_movein rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp if faction == 0, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store d_movein_nf

#delimit ;
coefplot (d_movein_f,  msymbol(Oh) mcolor(green)  pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(green)))
         (d_movein_nf, msymbol(Th) mcolor(orange) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(*0.9))), 
         vertical recast(scatter) keep(rel_w*) omitted
         order(rel_w1 rel_w2 rel_w3 rel_w4 rel_w5 rel_w6 rel_w7 rel_w8 rel_w9 rel_w10
               rel_w11 rel_w12 rel_w13 rel_w14 rel_w15 rel_w16 rel_w17 rel_w18 rel_w19 rel_w20 
               rel_w21 rel_w22 rel_w23 rel_w24 rel_w25 rel_w26 rel_w27 rel_w28 rel_w29 rel_w30 rel_w31)
         xtitle("Relative days to Community Stringent Measures") xlabel(, valuelabel labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash))
         ylabel(-20(5)10, labsize(small) tlength(0.8) grid glwidth(vthin) nogextend)
         legend(label(2 "With informal tie") label(4 "Without informal tie") position(8) ring(0) col(1))
         graphregion(fcolor(white) color(white) icolor(white) margin(small)) plotregion(margin(vsmall));
#delimit cr

****************
* Subfigure (3)
****************

* Generate interaction terms between time-to-event dummies and faction

forvalue i = 1/31 {
gen rel_w`i'_D = rel_w`i' * faction
}

forvalue i = 1/31 {
local j = `i' - 11
label var rel_w`i'_D "`j'"
}

qui: reghdfe d_movein rel_w1_D-rel_w9_D rel_w11_D-rel_w31_D rel_w10_D treat_csm wdsp temp prcp, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)
est store d_movein_ddd

#delimit ;
coefplot d_movein_ddd, vertical recast(scatter) keep(rel_w*_D) omitted
         order(rel_w1_D rel_w2_D rel_w3_D rel_w4_D rel_w5_D rel_w6_D rel_w7_D rel_w8_D rel_w9_D rel_w10_D
               rel_w11_D rel_w12_D rel_w13_D rel_w14_D rel_w15_D rel_w16_D rel_w17_D rel_w18_D rel_w19_D rel_w20_D 
               rel_w21_D rel_w22_D rel_w23_D rel_w24_D rel_w25_D rel_w26_D rel_w27_D rel_w28_D rel_w29_D rel_w30_D rel_w31_D)
         msymbol(Oh) mcolor(blue) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(blue))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash))
         ylabel(-20(5)10, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr
